const Base = require('./base.js');

module.exports = class extends Base {
  __before() {
    this.platformAdminService = think.rpc.platform.admin;
    this.platformId = think.config('platformId');
  }
  async logoutAction() {
    await this.setLoginUser(null);
    return this.success();
  }
  async loginAction() {
    const username = this.strVal('userName');
    const pwd = this.strVal('password');
    const adminData = await this.platformAdminService.queryAdminByUserNameAndPwd(this.platformId, username, pwd, {
      field: 'id,pwd'
    });
    if (!think.isEmpty(adminData)) {
      await this.setLoginUser({
        id: adminData.id,
        username
      });
      return this.success({
        username
      });
    }
    return this.fail('账号或密码错误');
  }
};
